<div th:replace="admin/module/_header"></div>
<div class="wrapper">
    <!-- 菜单栏模块 -->
    <div th:replace="admin/module/_sidebar"></div>
    <div class="content-wrapper">
        <style type="text/css" rel="stylesheet">
            .draft, .publish, .trash {
                list-style: none;
                float: left;
                margin: 0;
                padding-bottom: 10px
            }

            .box-body {
                padding: 0;
            }

            .box {
                border-top: 0;
            }
        </style>
        <section class="content-header">
            <h1>回复列表
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li>
                    <a data-pjax="true" href="/admin"><i
                            class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li class="active">回复管理</li>
            </ol>
        </section>
        <section class="content container-fluid">
            <div class="row">
                <div class="col-xs-12">
                    <div class="col-md-4 col-xs-12" style="margin-bottom: 10px;padding-left: 0;">
                        <button type="button" class="btn btn-danger" onclick="batchDelete()">
                            <i class="fa fa-remove"></i> 批量删除
                        </button>
                    </div>
                    <div class="col-md-8 col-xs-12"
                         style="margin-bottom: 10px; text-align:right;padding-left: 0; padding-right: 0;">
                        <form class="form-inline" action="/admin/comment">
                            <div class="form-group">
                                <input type="text" class="form-control" id="keywords" name="keywords"
                                       th:value="${keywords}" placeholder="请输入关键字">
                            </div>
                            <div class="form-group">
                                <select class="form-control" name="sort">
                                    <option value="createTime" disabled>排序字段</option>
                                    <option value="createTime" th:selected="${sort == 'createTime'}">回复时间</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <select class="form-control" name="order">
                                    <option value="desc" disabled>升序/降序</option>
                                    <option value="asc" th:selected="${order == 'asc'}">升序</option>
                                    <option value="desc" th:selected="${order == 'desc'}">倒序</option>
                                </select>
                            </div>
                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        </form>
                    </div>
                </div>
                <div class="col-xs-12">
                    <div class="box box-primary">
                        <div class="box-body table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" id="allSelect" onclick="doCheck()"></th>
                                    <th>回复人</th>
                                    <th>内容</th>
                                    <th class="col-md-2">时间</th>
                                    <th class="col-md-2">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="comment:${comments}" th:id="'comment-'+${comment.id}">
                                    <td><input type="checkbox" name="ids" th:value="${comment.id}"></td>
                                    <td><a th:href="'/user/'+${comment?.user?.id}">[[${comment?.user?.userDisplayName}]]</a></td>
                                    <td>
                                        <span style="cursor: pointer;" th:title="${comment.post.postTitle}" th:utext="${comment.commentContent}"></span>
                                    </td>
                                    <td th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}"></td>
                                    <td>
                                        <a th:href="'/post/'+${comment.post.id}" class="btn btn-success btn-xs"
                                           target="_blank">
                                            查看
                                        </a>
                                        <button class="btn btn-primary btn-xs "
                                                th:onclick="'replyShow('+${comment.id}+')'">回复
                                        </button>
                                        <button class="btn btn-danger btn-xs "
                                                th:onclick="'removeIt('+${comment.id}+')'">删除
                                        </button>

                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            <div class="no-margin pull-left">
                                第 [[${pageInfo.current}]] / [[${pageInfo.pages}]] 页
                            </div>
                            <ul class="pagination no-margin pull-right">
                                <li><a data-pjax="true" th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                       class="btn btn-sm"
                                       th:href="'/admin/comment?keywords='+${keywords}+'&sort='+${sort}+'&order='+${order}">
                                    首页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                       th:href="'/admin/comment?page='+${pageInfo.current-1}+'&keywords='+${keywords}+'&sort='+${sort}+'&order='+${order}">
                                    上一页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current == pageInfo.pages ? 'disabled' : ''}"
                                       th:href="'/admin/comment?page='+${pageInfo.current+1}+'&keywords='+${keywords}+'&sort='+${sort}+'&order='+${order}">
                                    下一页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current == pageInfo.pages ? 'disabled' : ''}"
                                       th:href="'/admin/comment?page='+${pageInfo.pages}+'&keywords='+${keywords}+'&sort='+${sort}+'&order='+${order}">
                                    尾页
                                </a>
                                </li>
                            </ul>
                        </div>

                    </div>
                </div>
            </div>
        </section>
        <!-- 回复弹出层 -->
        <div class="modal fade" id="commentReplyModal">
            <div class="modal-dialog">
                <div class="modal-content message_align">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">×</span></button>
                        <h4 class="modal-title">回复</h4>
                    </div>
                    <form method="post" action="/admin/comment/reply" id="commentReplyForm">
                        <div class="modal-body">
                            <textarea class="form-control comment-input-content" rows="5" id="commentContent"
                                      name="commentContent" style="resize: none"></textarea>
                            <div class="OwO"></div>
                        </div>
                        <div class="modal-footer">
                            <input type="hidden" id="id" name="id" value=""/>
                            <input type="hidden" id="userAgent" name="userAgent" value=""/>
                            <button type="button" class="btn btn-default"
                                    data-dismiss="modal">取消
                            </button>
                            <button type="button"
                                    class="btn btn-primary"
                                    onclick="replyIt()">确定
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <script>
            function removeIt(id) {
                layer.confirm('请确认是否删除', function (index) {
                    $.ajax({
                        type: 'DELETE',
                        url: '/admin/comment/delete',
                        async: false,
                        data: {
                            'id': id
                        },
                        success: function (data) {
                            if (data.code == 0) {
                                showMsg(data.msg, "error", 1000);
                            } else {
                                showMsg(data.msg, "success", 2000);
                                $('#comment-' + id).remove();
                            }
                        }
                    });
                    layer.close(index);
                });
            };

            function replyIt() {
                $.ajax({
                    type: 'POST',
                    url: '/admin/comment/reply',
                    async: false,
                    data: $('#commentReplyForm').serialize(),
                    success: function (data) {
                        if (data.code == 0) {
                            showMsg(data.msg, "error", 1000);
                        } else {
                            showMsgAndRedirect(data.msg, "success", 1000, "/admin/comment");
                            $('#commentReplyModal').modal('hide')
                        }
                    }
                });
            };

            function replyShow(id) {
                $('#userAgent').val(navigator.userAgent);
                $('#id').val(id);
                $('#commentReplyModal').modal();
            }

            function batchDelete() {
                var arr = [];
                $('input[name="ids"]:checked').each(function () {
                    arr.push($(this).val());
                });
                if (arr.length <= 0) {
                    showMsg('请选择需要删除的数据', "error", 1000);
                } else {
                    layer.confirm('请确认是否删除', function (index) {
                        $.ajax({
                            url: "/admin/comment/batchDelete?ids=" + arr,
                            type: "DELETE",
                            success: function (data) {
                                if (data.code == 0) {
                                    showMsg(data.msg, "error", 1000);
                                } else {
                                    showMsgAndReload(data.msg, "success", 2000);
                                }
                            }
                        });
                        layer.close(index);
                    });
                }
            }
        </script>
    </div>

</div>
<div th:replace="admin/module/_footer"></div>
